<template>
  <auth-button v-if="classType" :title="downloadButtonMsg" icon="iconfont iconxiazai" :size="size" :type="type" :label="downloadButtonMsg" :menuCode="menuCode" :perms="perms" @click="downloadSuccess"></auth-button>
  <auth-button v-else class="iconCircle" :title="$t('common.download')" icon="iconfont iconxiazai" :size="size" :type="type" :label="downloadButtonMsg" :menuCode="menuCode" :perms="perms" @click="downloadSuccess"></auth-button>
</template>

<script>
  import fileApi from '@/api/fileApi.js'
  import {downFile} from '@/utils/devUtils'
  import AuthButton from '@/components/auth/authButton'
  import httpConfig from '@/../config/httpConfig'
  export default {
    components: {AuthButton},
    props: {
      // 所属菜单Code-->全局唯一
      menuCode: {
        type: String,
        default: null
      },
      // 按钮权限标识，外部使用者传入
      perms: {
        type: String,
        default: null
      },
      // 文件ID
      fileID: {
        type: String,
        default: function () {
          return null
        }
      },
      // 文件管理服务下载地址
      downloadApi: {
        type: String,
        default: function () {
          return httpConfig.MID_FILE + '/api/file/file/download'
        }
      },
      // 下载按钮显示内容
      downloadButtonMsg: {
        type: String,
        default: function () {
          return ''
        }
      },
      size: {
        type: String,
        default: function () {
          return ''
        }
      },
      type: {
        type: String,
        default: function () {
          return null
        }
      },
      classType: {
        type: Boolean,
        default: function () {
          return false
        }
      }
    },
    data () {
      return {
      }
    },
    methods: {
      downloadSuccess () {
        fileApi.file.download({keyId: this.fileID}).then(res => {
          downFile(res)
        })
      }
    }
  }
</script>
